

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改优惠券</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div style="height: 42px;line-height: 42px;padding: 0 15px;border-bottom: 1px solid #f6f6f6;color: #333;border-radius: 2px 2px 0 0;font-size: 14px;">
            <span><i id="return" class="layui-icon layui-icon-return" style="padding-right: 10px;"></i></span>
            <span>修改优惠券</span>
        </div>

        <div class="layui-card-body" style="padding: 15px;">
            <form class="layui-form" action="" lay-filter="component-form-group" style="height: 100%">
                <input type="hidden" value="${couponDto.id}" name="id" name="id">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>优惠券名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" #{if couponDto.invalid==1}disabled="disabled"#{/if}  style="width: 300px" lay-verify="required" value="${couponDto.name}" autocomplete="off" placeholder="请输入优惠券名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>发放总量</label>
                    <div class="layui-input-block">
                        <input type="text" name="totalCount" #{if couponDto.invalid==1}disabled="disabled"#{/if} style="width: 300px" value="${couponDto.totalCount}" lay-verify="checkTotalCount" autocomplete="off" placeholder="最多100000张" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-form-label"><span style="color: red">*</span>优惠券类型</div>

                    <div class="layui-input-block">
                        <div class="layui-inline">
                            <input  type="radio" lay-filter="typeRadio"  name="type" value="1"  #{if couponDto.type==1} checked#{/if} disabled="disabled" title="现金券">
                        </div>
                        <div class="layui-inline">
                            <input type="text" name="val" id="val" lay-verify="val" autocomplete="off" disabled="disabled" value="${couponDto.val}" placeholder="请输入现金值,单位元" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-input-block">
                        <div class="layui-inline">
                            <input type="radio" lay-filter="typeRadio" name="type" value="0"  title="免费券" #{if couponDto.type==0} checked#{/if} disabled="disabled">
                        </div>
                    </div>
                </div>

                <div class="layui-inline">
                    <div class="layui-form-label"><span style="color: red">*</span>使用场景</div>
                    <div class="layui-input-block">
                        <input type="radio" name="use" lay-filter="use" value="0" title="自用" #{if couponDto.useType==0} checked#{/if} disabled="disabled">
                        <input type="radio" name="use" lay-filter="use" value="1"  title="赠送" #{if couponDto.useType==1} checked#{/if} disabled="disabled">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-form-label"><span style="color: red">*</span>每人限领次数</div>

                    <div class="layui-input-block">
                        <div class="layui-inline">
                            <input  type="radio" lay-filter="limitRadio"  name="limit"  #{if couponDto.limitNum==0} checked#{/if} disabled="disabled" checked title="不限次数">
                        </div>

                    </div>
                    <div class="layui-input-block">
                        <div class="layui-inline">
                            <input type="radio" lay-filter="limitRadio" name="limit"  title="限领" #{if couponDto.limitNum>0} checked#{/if} disabled="disabled">
                        </div>
                        <div class="layui-inline">
                            <input type="text" name="val" id="val" lay-verify="val" autocomplete="off" placeholder="请输入次数"  value="${couponDto.limitNum}" disabled="disabled" class="layui-input">
                        </div>
                        <div class="layui-inline">
                            次<span style="padding-left:20px;color: red">限制在1~100之间的整数</span>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-form-label"><span style="color: red">*</span>用券时间</div>

                    <div class="layui-input-block">
                        <div class="layui-inline">
                            <input  type="radio" lay-filter="validTypeRadio"  name="validType" value="0"  #{if couponDto.validType==0} checked#{/if} disabled="disabled" title="">
                        </div>
                        <div class="layui-inline" ><input type="text" name="startTime" id="" #{if couponDto.validType==0} value="${new Date(couponDto?.startTime).format('yyyy-MM-dd HH:mm:ss')}" #{/if} disabled="disabled" placeholder="开始时间" autocomplete="off" class="layui-input"></div>
                        <div class="layui-inline" >——</div>
                        <div class="layui-inline" ><input type="text" name="endTime" id="endTime" #{if couponDto.validType==0} value="${new Date(couponDto?.endTime).format('yyyy-MM-dd HH:mm:ss')}" #{/if} disabled="disabled" placeholder="结束时间" autocomplete="off" class="layui-input"></div>

                    </div>
                    <div class="layui-input-block">
                        <div class="layui-inline">
                            <input type="radio" lay-filter="validTypeRadio" name="validType" value="1" #{if couponDto.validType==1} checked#{/if} disabled="disabled" title="领券当日起">
                        </div>
                        <div class="layui-inline">
                            <input type="text" name="validDay" id="validDay" lay-verify="validDay" autocomplete="off" placeholder="请输入天数" #{if couponDto.validType==1} value="${couponDto?.validDay}"#{/if} disabled="disabled" class="layui-input">
                        </div>
                        <div class="layui-inline">
                            天内可用
                        </div>
                    </div>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-label"><span style="color: red">*</span>派发方式</div>
                    <div class="layui-input-block">
                        <input type="radio" name="dispatchType" lay-filter="dispatchType" value="0" title="公开链接"  #{if couponDto.dispatchType==0} checked#{/if} disabled="disabled">
                        <input type="radio" name="dispatchType" lay-filter="dispatchType" value="1" title="隐藏链接"  #{if couponDto.dispatchType==1} checked#{/if} disabled="disabled">
                    </div>
                </div>
                #{if couponDto.invalid==1}
                    <div class="layui-form-item" style="padding-left: 35px;">
                        <span style="color: red">*</span>失效状态&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red">已失效</span>
                    </div>
                #{/if}
                #{if couponDto.invalid==0}
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <div class="layui-footer" style="left: 0;">
                            <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            <button class="layui-btn #{if !toolsUtils.checkBtn('/coupon/updateInvalid')} layui-hide #{/if}" lay-submit="" lay-filter="invalid">使失效</button>
                            #{if  couponDto.dispatchType==0}
                                <button class="layui-btn #{if !toolsUtils.checkBtn('/coupon/tg')} layui-hide #{/if}" lay-submit="" lay-filter="tg">推广</button>
                            #{/if}
                        </div>
                    </div>
                </div>
                #{/if}
            </form>
        </div>
    </div>
</div>
<input type="hidden" id="path" value="${path}">
<input type="hidden" id="qrUrl" value="${qrUrl}">
<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate','layer','element','layedit'], function(){
        var $ = layui.$
                ,admin = layui.admin
                ,element = layui.element
                ,layer = layui.layer
                ,laydate = layui.laydate
                ,form = layui.form;

        $(document).on('click','#return',function(){
            window.location.href = "/coupon/list";
        });


        /* 监听提交 */
        form.on('submit(component-form-demo1)', function(data){
            var data=data.field;

            $.post("/coupon/saveCoupon", data, function (result) {
                if (result.code > 0) {
                    layer.msg(result.msg);
                } else {
                    window.location.href = "/coupon/list";
                }
            });
            return false;

        });
        form.on('submit(invalid)', function(data){
            var data=data.field;

            layer.confirm('真的使这个优惠券失效么',{icon: 7, title:'提示',skin: 'layui-layer-molv' ,anim: 4},function(index){
                //obj.del();
                layer.close(index);
                $.get("/coupon/updateInvalid?invalid=1&id="+data.id,function (result) {
                    if (result.code > 0) {
                        layer.msg(result.msg, {icon:2});
                        return false;
                    }else {
                        layer.msg(result.msg, {icon:1});
                        window.location.reload();
                        //obj.del();
                    }
                });
            });
            return false;

        });

        form.on('submit(tg)', function(data){
            var qrUrl=$("#qrUrl").val();
            var path=$("#path").val();
            layer.open({
                type: 1,
                title:false,
                closeBtn: 0, //不显示关闭按钮
                anim: 2,
                shadeClose: true, //开启遮罩关闭
                content: "<img src='"+qrUrl+path+"'>"
            });
           // layer.msg("给出二维码", {icon:1});
            return false;
        });


    });

</script>
</body>
</html>
